package ModelLayer;
import java.util.ArrayList;

public class DVDLager
{
    private ArrayList<DVD> dvdliste;
    private DVD dvd1;
    private static DVDLager _instance;

    /**
     * Constructor for objects of class DVDKartotek
     */
    public DVDLager()
    {
        dvdliste = new ArrayList<DVD>();
        dvd1 = null;
    }
    
    public static DVDLager getInstance()
    {
        if(_instance == null)
        {
            _instance = new DVDLager();
        }
        return _instance;
    }
    
    public void addDVD(DVD d)
    {
        dvdliste.add(d);
    }
    
    public void deleteDVD(long id)
    {
        dvd1 = getDvd(id);
        dvdliste.remove(dvd1);
    }
    
    public DVD getDvd(long id)
    {
        for(DVD d : dvdliste)
        {
            if(d.getID() == id)
            dvd1 = d;
        }
        return dvd1;
    }
    
    public DVD getDvdByTitle(String title)
    {
        for (DVD d : dvdliste)
        {
            if (d.getTitle() == title)
                dvd1 = d;
        }
        
        return dvd1;
    }
    
    public ArrayList<Long> getDvdID()
    {
        ArrayList<Long> dvdId = new ArrayList<Long>();
        for(DVD d : dvdliste)
        {
            dvdId.add(d.getID());
        }
        
        return dvdId;
    }
    
    public void updateDvd(long id, String title, String artist, String releaseDate)
    {
        DVD dvd = null;
        for(DVD d : dvdliste)
        {
            if(d.getTitle() == title)
            dvd = d;
        }
        dvd.setTitle(title);
    }
    
    public ArrayList<DVD> listAllDvds()
    {
        return dvdliste;
    }
}


